<template>
	<view>
		<view class="p-3 flex align-center">
			<view class="flex-1 flex flex-column align-center text-muted font">
				<image :src="user.imgUrl"   @click="changeIcon" class="rounded-circle  flex-shrink mr-3 justify-center" style="width: 120rpx;height: 120rpx; ;"></image>
			</view>
		</view>
		<view class="f-divider"></view>
		<view class="p-3 flex align-center">
			<view class="flex-1 flex flex-column text-muted font">
				<view class="flex align-end">
					<input class="uni-input bg-light rounded mb-4" placeholder="昵称" type="text" v-model="user.name" />
				</view>
				<view class="flex align-end">
					<input class="uni-input bg-light rounded mb-4" placeholder="密码" type="password" v-model="user.password" />
				</view>
				<view class="flex align-end align-center justify-center font-md rounded-circle" @click="changeInfo">
					确认修改
				</view>
			</view>
		</view>
		<view class="f-divider"></view>
		<view class="mx-3 mt-4 bg-main text-white flex align-center justify-center font-lg rounded-circle" hover-class="bg-main-hover"
		 @click="logout">
			退出登录
		</view>
	</view>
</template>

<script>
import uniListItem from '@/components/uni-ui/uni-list-item/uni-list-item.vue';
	export default {
		data() {
			return {
			}
		},computed: {
			// ...mapState({
			// 	user: state => state.user
			// }),
			user(){
				this.$store.state.user.url = this.$store.state.user.url? this.$store.state.user.url:'/static/14.jpg'
				return this.$store.state.user
				}
			},	
		onShow(){
			console.log(this,this.user.imgUrl)
		},
		methods: {
			logout() {
				this.$store.dispatch('logout').then(res => {
					uni.showToast({
						title: '成功退出',
						icon: 'none'
					});
				})
			},
			changeInfo(){
				this.$H.post('/user/changeInfo',this.user, {
					token: true
				}).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					});
				})
			},
			changeIcon(){
				
				uni.chooseImage({
					count: 1,
					success: (re) => {
					this.$H.upload("/user/changeIcon", {
						filePath: re.tempFiles[0].path
					}).then(res => {
						uni.redirectTo({
							url: "/pages/setting/setting"
						})
					})
					}
				})
	}
	},
	}
</script>

<style>

</style>
